package com.jf.identity.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 分页组件
 *
 * @param <T> 页面数据类型
 * @author FCG
 */
public class PageBean<T> implements Serializable {
    private static final long serialVersionUID = 1903515543042306495L;
    /**
     * 当前页码
     */
    private int currentPage;
    /**
     * 单页显示数据条数
     */
    private int pageSize;
    /**
     * 总页数
     */
    private int totalPage;
    /**
     * 总数据行数
     */
    private int totalRow;
    /**
     * 当前页起始数据位置
     */
    private int startIndex;
    /**
     * 页面数据
     */
    private List<T> pageData = new ArrayList<>();

    public PageBean() {
        currentPage = 1;
        pageSize = 20;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalPage() {
        int totalPage = totalRow / pageSize;
        return (totalRow % pageSize == 0) ? totalPage : ++totalPage;
    }

    public int getTotalRow() {
        return totalRow;
    }

    public void setTotalRow(int totalRow) {
        this.totalRow = totalRow;
    }

    public int getStartIndex() {
        return (currentPage - 1) * pageSize;
    }

    public void setStartIndex(int startIndex) {
        this.startIndex = startIndex;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public List<T> getPageData() {
        return pageData;
    }

    public void setPageData(List<T> pageData) {
        this.pageData = pageData;
    }

}
